clear
cap log close

cd "D:\Dropbox\Work\Research\CreditCardABSRewrite\Draft\ReplicationFiles\Tab_4\Stata"


local today = "`c(current_date)'"
log using "Table_04_Log.log", text append

import delimited "Data_Table_04.csv"

* generate year/month
gen ym = ym(year,month)
format ym %tm
tsset ym

* generate indicators for subperiods
generate pre=1 if year<2007
generate cri=1 if year>2006 & year<2010
generate post=1 if year>2009 & year<2021

* generate diffs
gen Driskprem_a = D.riskprem_a*100.0
gen Driskprem_b = D.riskprem_b*100.0
gen Driskprem_c = D.riskprem_c*100.0
gen Dcptbillspread = D.cptbillspread*100.0
gen Daaa10yr = D.aaa10yr*100.0
gen Dbaa10yr = D.baa10yr*100.0
gen Dhy = D.hy*100.0

* Table 4

*****************
* A Tranche
* All
regress Driskprem_a Dcptbillspread Daaa10yr Dbaa10yr Dhy
loc AdjR2 = e(r2_a)
newey2 Driskprem_a Dcptbillspread Daaa10yr Dbaa10yr Dhy, lag(4) force
outreg2 using Tab4_A, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("A Tranche") ctitle("All") drop(Driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) word replace

* 2000-2006
regress Driskprem_a Dcptbillspread Daaa10yr Dbaa10yr Dhy if pre==1
loc AdjR2 = e(r2_a)
newey2 Driskprem_a Dcptbillspread Daaa10yr Dbaa10yr Dhy, lag(4) force, if pre==1
outreg2 using Tab4_A, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("A Tranche") ctitle("2000-2006") drop(Driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) word 
* 2007-2009
regress Driskprem_a Dcptbillspread Daaa10yr Dbaa10yr Dhy if cri==1
loc AdjR2 = e(r2_a)
newey2 Driskprem_a Dcptbillspread Daaa10yr Dbaa10yr Dhy, lag(4) force, if cri==1
outreg2 using Tab4_A, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("A Tranche") ctitle("2007-2009") drop(Driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) word 
* 2010-2020
regress Driskprem_a Dcptbillspread Daaa10yr Dbaa10yr Dhy if post==1
loc AdjR2 = e(r2_a)
newey2 Driskprem_a Dcptbillspread Daaa10yr Dbaa10yr Dhy, lag(4) force, if post==1
outreg2 using Tab4_A, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("A Tranche") ctitle("2010-2020") drop(Driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) word 


*******************
* B Tranche
* All
regress Driskprem_b Dcptbillspread Daaa10yr Dbaa10yr Dhy
loc AdjR2 = e(r2_a)
newey2 Driskprem_b Dcptbillspread Daaa10yr Dbaa10yr Dhy, lag(4) force
outreg2 using Tab4_B, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("B Tranche") ctitle("All")  drop(Driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) word replace
* 2000-2006
regress Driskprem_b Dcptbillspread Daaa10yr Dbaa10yr Dhy if pre==1
loc AdjR2 = e(r2_a)
newey2 Driskprem_b Dcptbillspread Daaa10yr Dbaa10yr Dhy, lag(4) force, if pre==1
outreg2 using Tab4_B, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("B Tranche") ctitle("2000-2006") drop(Driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) word 
* 2007-2009
regress Driskprem_b Dcptbillspread Daaa10yr Dbaa10yr Dhy if cri==1
loc AdjR2 = e(r2_a)
newey2 Driskprem_b Dcptbillspread Daaa10yr Dbaa10yr Dhy, lag(4) force, if cri==1
outreg2 using Tab4_B, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("B Tranche") ctitle("2007-2009") drop(Driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) word 
* 2010-2020
regress Driskprem_b Dcptbillspread Daaa10yr Dbaa10yr Dhy if post==1
loc AdjR2 = e(r2_a)
newey2 Driskprem_b Dcptbillspread Daaa10yr Dbaa10yr Dhy, lag(4) force, if post==1
outreg2 using Tab4_B, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("B Tranche") ctitle("2010-2020") drop(Driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) word 


*******************
* C Tranche
* All
regress Driskprem_c Dcptbillspread Daaa10yr Dbaa10yr Dhy
loc AdjR2 = e(r2_a)
newey2 Driskprem_c Dcptbillspread Daaa10yr Dbaa10yr Dhy, lag(4) force
outreg2 using Tab4_C, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("C Tranche") ctitle("All") drop(Driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) word replace
* 2000-2006
regress Driskprem_c Dcptbillspread Daaa10yr Dbaa10yr Dhy if pre==1
loc AdjR2 = e(r2_a)
newey2 Driskprem_c Dcptbillspread Daaa10yr Dbaa10yr Dhy, lag(4) force, if pre==1
outreg2 using Tab4_C, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("C Tranche") ctitle("2000-2006") drop(Driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) word 
* 2007-2009
regress Driskprem_c Dcptbillspread Daaa10yr Dbaa10yr Dhy if cri==1
loc AdjR2 = e(r2_a)
newey2 Driskprem_c Dcptbillspread Daaa10yr Dbaa10yr Dhy, lag(4) force, if cri==1
outreg2 using Tab4_C, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("C Tranche") ctitle("2007-2009") drop(Driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) word 
* 2010-2020
regress Driskprem_c Dcptbillspread Daaa10yr Dbaa10yr Dhy if post==1
loc AdjR2 = e(r2_a)
newey2 Driskprem_c Dcptbillspread Daaa10yr Dbaa10yr Dhy, lag(4) force, if post==1
outreg2 using Tab4_C, stats(coef tstat) noaster addstat(AdjR2, `AdjR2') title("C Tranche") ctitle("2010-2020") drop(Driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) word 

log close